﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace GrainManage.Server.Cache
{
    public class CachedStatusMessage
    {
        private static object lockObj = new object();
        private static readonly Dictionary<int, string> ErrorMessage = new Dictionary<int, string>();
        public static string GetMessage(int statusCode)
        {
            try
            {
                if (!ErrorMessage.Keys.Contains(statusCode))
                {
                    var service = ObjectFactory.StatusService;
                    string message = service.GetMessage(statusCode);
                    lock (lockObj)
                    {
                        if (!ErrorMessage.Keys.Contains(statusCode))
                        {
                            ErrorMessage[statusCode] = message;
                        }
                    }
                }
                return ErrorMessage[statusCode];
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }
    }
}